<template>
	<div class="distribution">
		<div class="html">
			铺货类型
			<select v-model="selecteds" class="fen" @change="configData(selecteds)">
						<option v-for="(item,index) in gui" :value="index">{{item.name}}</option>
			</select>
			
			<!--<select v-model="value" @change="configData(index)" class="fen" placeholder="请选择轨道">
                <option v-for="(item,index) in gui" :value="item.index" :key="item.value">{{item.name}}</option>
            </select>-->
            
		</div>
		<div class="content">
			<div class="C_d" v-for='(item,index) in list' :key="index">
				<div class="C_dd" >
					<input type="checkbox" v-model="item.chosed" class="cheboxsty">
					<div class="title"><span>{{item.goodsName}}</span><span>{{item.showSkuName}}</span></div>
				</div>
				
				<div class="shu">
					<img src="../assets/jianhao.png" @click="jian(index)">
					<span>{{item.count}}</span>
					<img src="../assets/jia.png" @click="jia(index)">
				</div>
				<div class="qian">￥{{item.storePrice}}</div>
			</div>
	
				
		</div>
		<div class="footer">
			<input type="checkbox" checked class="cheboxsty" disabled="true">
			确认{{shu}}件商品{{zong}}元 加 小柜 {{guizi}}元
			<button @click="tijiao" :disabled='show'>提交订单</button>
		</div>
	</div>
</template>

<script>
	import { BaseUrl } from '../Baseurl/common.js';
	export default{
		data(){
			return{
		        gui:[],
		        list:[],
		        id:'',
		        guizi:"",
			    selecteds: 0,
			    shu:0,
			    zong:0,
			    partnerId:'',
			    show:true,
			    isShow:''
			 }
		},
		created(){
			this.partnerId = this.$route.query.partnerId
			this.isShow = this.$route.query.isShow
			
			if(this.isShow == 'show'){
				this.show = false
			}else{
				this.shoe = true
			}
//			var url = BaseUrl + 'partner2/listCabinet'
//			this.$http.get(url).then(res=>{
//					if(res.data.code == '10000'){
//						this.gui = res.data.data
//						this.id = this.gui[0].id
//						
//		        		var title = this.gui[0].name
//		        		localStorage.setItem('title', title)
//	var url = BaseUrl + 'partner2/listCabinetItems?cabinetId='+ this.id
//				this.$http.get(url).then(res=>{
//					if(res.data.code == '10000'){
//						this.guizi = res.data.data.cabinetMoney
//						
//		        		localStorage.setItem('guizi', this.guizi)
//						this.list = res.data.data.list
//						
//						var zong = this.list
//						var newaa=0
//						var cartss=0
//						for (var i = 0; i < zong.length; i++) {
//				          newaa += zong[i].count * zong[i].storePrice
//				          cartss += zong[i].count
//				      	}
//						this.zong = newaa.toFixed(2)
//						this.shu = cartss
//				}
//		    })
//					}
//			})
			
			
			var url = BaseUrl + "partner/order2/submitPuhuoView?partnerId=" + this.partnerId
			this.$http.get(url).then(res=>{
//				console.log(res.data.data)
				if(res.data.code == 10000){
					if(JSON.stringify(res.data.data) != '{}'){
						var jsonStr = JSON.stringify(res.data.data)
						localStorage.setItem('order', jsonStr)
						this.$router.push({
								path: '/echoorder'
						})
					}else{
						var url = BaseUrl + 'partner2/listCabinet'
						this.$http.get(url).then(res=>{
								if(res.data.code == '10000'){
									this.gui = res.data.data
									this.id = this.gui[0].id
									
					        		var title = this.gui[0].name
					        		localStorage.setItem('title', title)
				var url = BaseUrl + 'partner2/listCabinetItems?cabinetId='+ this.id
							this.$http.get(url).then(res=>{
								if(res.data.code == '10000'){
									this.guizi = res.data.data.cabinetMoney
									
					        		localStorage.setItem('guizi', this.guizi)
									this.list = res.data.data.list
									
									var zong = this.list
									var newaa=0
									var cartss=0
									for (var i = 0; i< zong.length; i++) {
							          newaa += zong[i].count * zong[i].storePrice
							          cartss += zong[i].count
							      	}
									this.zong = newaa.toFixed(2)
									this.shu = cartss
							}
					    })
								}
						})
						
					}
				}
			})
			
			
			
			
			
		},
		methods:{
			configData (index) {
//		        console.log(this.gui[index].id)
		        this.id = this.gui[index].id
		        var title = this.gui[index].name
		        localStorage.setItem('title', title)
//		        console.log(this.id)
		        var url = BaseUrl + 'partner2/listCabinetItems?cabinetId='+ this.id
				this.$http.get(url).then(res=>{
					if(res.data.code == '10000'){
						this.guizi = res.data.data.cabinetMoney
						this.list = res.data.data.list
						
						var zong = this.list
						var newaa=0
						var cartss=0
						for (var i = 0; i < zong.length; i++) {
				          newaa += zong[i].count * zong[i].storePrice
				          cartss += zong[i].count
				      	}
						this.zong = newaa.toFixed(2)
						this.shu = cartss
				}
		        })
				
				
				
		     },
			tijiao:function(){
				
				
				var zong = this.list
				var aa = []
				var a=''
				var b=[]
		        for(var i = 0,l=zong.length; i < l; i++){
		            if(zong[i].chosed == false){
		                continue;
		            }
		            aa[i] = zong[i];
		        }
				for (var i = 0; i < aa.length; i++) {
			      a = {
			        skuId: aa[i].skuId,
			        count: aa[i].count
			      }
			      b.push(a);
			   }
		        var jsonStr1 = JSON.stringify(b)
		        localStorage.setItem('jsonStr1', jsonStr1)
		        	this.$router.push({
						path: '/message?partnerId=' + this.partnerId
					})
	
			},
			jia:function(index){
				this.list[index].count++
				var zong = this.list
						var newaa=0
						var cartss=0
						for (var i = 0; i < zong.length; i++) {
				          newaa += zong[i].count * zong[i].storePrice
				          cartss += zong[i].count
				      	}
						this.zong = newaa.toFixed(2)
						this.shu = cartss
			},
			jian:function(index){
				if(this.list[index].count >1){
					this.list[index].count--
				}
				var zong = this.list
						var newaa=0
						var cartss=0
						for (var i = 0; i < zong.length; i++) {
				          newaa += zong[i].count * zong[i].storePrice
				          cartss += zong[i].count
				      	}
						this.zong = newaa.toFixed(2)
						this.shu = cartss
			}
		},
		watch:{
				list:{
					handler:function  (){
						var totall=0;
						var carts=0;
						for(var i=0; i<this.list.length;i++){

							if (this.list[i].chosed){
								totall+=this.list[i].count * this.list[i].storePrice;
								carts += this.list[i].count
								this.list[i].count
								
							}
						}
						this.zong=totall.toFixed(2);
						this.shu = carts;
					},
					deep:true
				}
		},
//		mounted(){
//		document.getElementsByClassName("fen")[0][1].selected=true;
//		},
		
	}
</script>

<style scoped="scoped">
	.distribution{
		width: 100%;
		height: 100%;
		overflow-y: auto;
	}
	.html{
		width: 100%;
		padding: 0.2rem 0.2rem;
		padding-bottom: 0.3rem;
		border-bottom: 1px solid #333333;
	}
	.fen{
		width: 75%;
		height: 0.6rem;
		margin-left: 0.2rem;
		outline: none;
	}
	.content{
		width: 100%;
	}
	.C_d{
		padding: 0.2rem 0.2rem;
		box-sizing: border-box;
		border-bottom: 1px solid #333333;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.C_dd{
		display: flex;
		align-items: center;
	}
	.cheboxsty{
		margin-right: 0.2rem;
	}
	.title{
		width: 2rem;
		text-align: center;
		
	}
	.title span{
		width: 2rem;
		display: block;
		overflow : hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
	.shu{
		display: flex;
		/*align-items: center;*/
	}
	.shu span{
		width: 0.5rem;
		text-align: center;
	}
	.shu img{
		width: 0.4rem;
		height: 0.4rem;
		margin: 0 0.1rem;
	}
	.qian{
	}
	.footer{
		padding: 0.2rem 0.2rem;
		box-sizing: border-box;
		border-bottom: 1px solid #333333;
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: 0.3rem;
	}
	button{
		width: 2rem;
		height: 0.8rem;
		margin-left: 10%;
	}
</style>